proc version {xlib from type is_subject subject body err thread priority x} {

if {[string length $body]>1} {
	set from "[node_and_server_from_jid $from]/$body"
}
set to "$from"

::xmpp::sendIQ $xlib get \
	-query [::xmpp::xml::create query -xmlns jabber:iq:version] \
	-to $to \
	-timeout [expr {$options(timeout)*1000}] \
	-command [list version:reply $xlib $to $from $type]

}

proc version:reply {xlib to from type status xml} {
	if {![string equal $status ok]} {
		return
    }
    
    ::xmpp::xml::split $xml tag xmlns attrs cdata subels

    if {[string equal $xmlns jabber:iq:version]} {
		foreach item $items {
			::xmpp::xml::split $item tag xmlns attrs cdata subels

			switch -- $tag {
			    name    {set userinfo(clientname,$jid)    $cdata}
			    version {set userinfo(clientversion,$jid) $cdata}
			    os      {set userinfo(os,$jid)            $cdata}
			    default {debugmsg userinfo "Unknown iq:version tag '$tag'"}
			}
			
			if {[info exists name]!=1} {set name [::msgcat::mc "unknown client"]}
			if {[info exists version]!=1} {set version [::msgcat::mc "unknown version"]}
			if {[info exists os]!=1} {set os [::msgcat::mc "unknown os"]}
		}
		if {$type=="groupchat"} {
			if {"$from"=="$to"} {
				gm $xlib "$from" "ты используеш $name $version на $os"
			} else {
				gm $xlib "$from" "[resource_from_jid $to] использует $name $version на $os"
			}
		} else {
			if {"$from"=="$to"} {
				pm $xlib "$from" "ты используеш $name $version на $os"
			} else {
				pm $xlib "$from" "[resource_from_jid $to] использует $name $version на $os"
			}
		}
    }
}

::msgcat::mcset ru "unknown client" "неизвестный клиент"
::msgcat::mcset ru "unknown version" "неизвестной версии"
::msgcat::mcset ru "unknown os" "неизвестной ОС"

::msgcat::mcset ru "version" "версия"
::msgcat::mcset en "version" "version"
cmd::add [::msgcat::mc "version"] version